package com.cxcy.swustlearner.controller;

import com.cxcy.swustlearner.pojo.User;
import com.cxcy.swustlearner.service.RegisterService;
import com.cxcy.swustlearner.utils.Md5;
import common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @RequestMapping("/register")
    public Result register(@RequestBody User user) {
        System.out.println(user.getUsername());
        if(user.getUsername()==null||user.getPassword()==null)
        {
            return Result.fail("请确保每一项非空");
        }
        user.setPassword(Md5.md5(user.getPassword()));
        registerService.register(user);
        return Result.success("注册成功");
    }
}